// localLifePackage/pages/superOrderDetail/superOrderDetail.js
var common = require("../../../common/common.js").common;

var app = getApp();

Page({
    /**
     * 页面的初始数据
     */
    data: {
        title: "订单详情"
    },
    //获取去右侧胶囊的信息
    getHeader() {
        let menuRect = wx.getMenuButtonBoundingClientRect();
        this.setData({
            topBarHeight: menuRect.height,
            topBarTop: menuRect.top
        });
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        let page_x = getCurrentPages().length;
        this.setData({
            page_x: page_x
        });
        this.getHeader();
        this.getBase();
        this.setData({
            order_sn: options.order_sn,
            domain: app.globalData.domain.slice(0, -10)
        });
        this.getOrder_detail();
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {},
    //申请退款
    cancel_order2() {
        let that = this;
        // let ids=[];
        // let order_info = this.data.details.order_info;
        // order_info.map(x=>{
        //   ids.push(x.id);
        // })
        // console.log(JSON.stringify(that.data.details));
        // console.log(encodeURIComponent(JSON.stringify(that.data.details)));
        // return;
                wx.navigateTo({
            url: "/localLifePackage/pages/RefundApplication/RefundApplication?info=" + encodeURIComponent(JSON.stringify(that.data.details))
        });
    },
    //全局基础配置信息
    getBase: function() {
        var that = this;
        common.request({
            endpoint: "set/app_base",
            method: "get",
            data: {},
            success: res => {
                var goodsListStyle = that.data.goodsListStyle;
                wx.setNavigationBarColor({
                    frontColor: "#ffffff",
                    backgroundColor: res.extra.color_main
                });
                that.setData({
                    color_main: res.extra.color_main,
                    color_minor: res.extra.color_minor,
                    apptitle: res.extra.title,
                    style: res.extra.style,
                    timeStyle: {
                        height: 32,
                        mainColor: res.extra.color_main
                    },
                    goodsListStyle: {
                        ...goodsListStyle,
                        mainColor: res.extra.color_main
                    }
                });
            }
        });
    },
    getOrder_detail: function() {
        var that = this;
        common.request({
            endpoint: "v1/Supermarket/order/view",
            method: "post",
            data: {
                order_sn: this.data.order_sn
            },
            success: res => {
                this.setData({
                    details: res.extra
                });
                let flag = false;
                res.extra.items.forEach((item, index) => {
                    if (item.status == 1) {
                        flag = true;
                    }
                });
                this.setData({
                    details: res.extra,
                    flag: flag
                });
            }
        });
    },
    order_copy: function(e) {
        var copy = e.currentTarget.dataset.copy;
        wx.setClipboardData({
            data: copy,
            success: function(res) {
                wx.showToast({
                    title: "复制成功",
                    icon: "succes",
                    duration: 1e3,
                    mask: true
                });
            }
        });
    },
    index_call: function(e) {
        wx.makePhoneCall({
            phoneNumber: e.currentTarget.dataset.phone
        });
    }
});